package com.zib.bilibili.view.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.zib.bilibili.R;
import com.zib.bilibili.base.BaseMvpFragment;
import com.zib.bilibili.base.CommonAdapter;
import com.zib.bilibili.base.ViewHolder;
import com.zib.bilibili.bean.GifttopBean;
import com.zib.bilibili.presenter.GiftTopPresenter;
import com.zib.bilibili.view.IFragment;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/7/7.
 */
public class GiftTopFragment extends BaseMvpFragment<IFragment, GiftTopPresenter> implements IFragment {
    @Bind(R.id.listview_fragment_onlyfragment)
    ListView listviewFragmentOnlyfragment;
    private int roomid;


    public static GiftTopFragment newInstance(int roomid) {

        Bundle args = new Bundle();
        args.putInt("roomid",roomid);
        GiftTopFragment fragment = new GiftTopFragment();
        fragment.setArguments(args);
        return fragment;
    }
    @Override
    protected GiftTopPresenter initPresenter() {
        roomid = getArguments().getInt("roomid");
        return new GiftTopPresenter(roomid);
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_onlylistview;
    }

    @Override
    public void initView() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    public void loadNetworkForListview(List<GifttopBean.DataBean.ListBean> list) {
        listviewFragmentOnlyfragment.setAdapter(new CommonAdapter<GifttopBean.DataBean.ListBean>(getContext(), list, R.layout.item_listview_gifttop) {
            @Override
            public void convert(ViewHolder helper, GifttopBean.DataBean.ListBean item) {
                helper.setText(R.id.textview_item_gifttop_name, item.getUname());
                helper.setText(R.id.textview_item_gifttop_num, item.getCoin() + "");
            }
        });
    }

    @Override
    public void onSuccess(Object... objects) {
        loadNetworkForListview(((GifttopBean) objects[0]).getData().getList());
    }

    @Override
    public void onFaile() {

    }
}
